layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 承运商档案管理
     */
    var BasicCarrier = {
        tableId: "basicCarrierTable"
    };

    /**
     * 初始化表格的列
     */
    BasicCarrier.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {field: 'operateName', sort: true, title: '项目'},
            {field: 'carrierName', sort: true, title: '单位名称'},
            {field: 'types', sort: true, title: '类型'},
            {field: 'abbreviation', sort: true, title: '简称'},
            {field: 'city', sort: true, title: '城市'},
            {align: 'center', toolbar: '#tableBar', title: '操作',fixed: 'right',width:70}
        ]];
    };

    /**
     * 点击查询按钮
     */
    BasicCarrier.search = function () {
        var queryData = {};
        queryData['operateId'] = $("#operateId").val();
        queryData['condition'] = $("#condition").val();
        table.reload(BasicCarrier.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + BasicCarrier.tableId,
        url: Feng.ctxPath + '/basicCarrier/list?v1=1',
        page: true,
        limit: 20,
        height: "full-60",
        toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
        cellMinWidth: 100,
        cols: BasicCarrier.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        BasicCarrier.search();
    });
    
    //回填数据
    function confirm(data){
    	parent.BasicCarrierInfoDlg.data.carrierId = data.id;
    	parent.BasicCarrierInfoDlg.data.carrierName = data.carrierName;
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    }
    
    // 双击行事件
    table.on('rowDouble(' + BasicCarrier.tableId + ')', function (obj) {
        var data = obj.data;
    	confirm(data);
    });

    // 工具条点击事件
    table.on('tool(' + BasicCarrier.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'confirm') {
        	confirm(data);
        } 
    });
    
});
